<?php
/**
 * EsayADT 简单应用框架
 *  
 * @version   :  1.0
 * @author    :  sports98@gmail.com
 * @file      :  basefunction.php
 * @createTime:  Wed Mar 03 09:57:54 CST 2010
 * 
 */


/**
 * 异常抛出专用字串
 * @final $string;
 * @return String;
 */
function _ExceptionString($string)
{
	return "<div style='border:1px dotted #E89B00;margin:3px;text-align:left;background-color:#E8E8E8;padding:3px;font-size:12px;padding-left:10px;'><font face='webdings'>4</font>$string</div>";
}


/**
 * 载入需要的Header File
 *
 * @param (String) $file
 * @param (Boolean) $include_once
 * @return Void
 */
function _include($file,$include_once=true){
	$includTag = "";
	if($include_once){
		_debug(array(__FILE__,__LINE__,'Include_Once '.$file.".php"));
		$includTag = include_once $file.".php";
	}
	else{
		$includTag = include $file.".php";
	}
	//echo gettype($includTag);
	if(gettype($includTag) == "boolean" || strlen($includTag)!=MD5LEN){
		if(TRHOWEXCEPTION)throw new Exception(_ExceptionString("Load File '$file' fail !"));
	}
}



/**
 * 载入可执行库LIB文件
 *
 * @param (String) $file
 * @link _include
 * @return Void
 */
function _load($file){
	try{
		_include($file);		
	}
	catch (Exception $e){
		echo $e->getMessage();
	}
}


function _importClass($className){
	$prefix = getcwd().DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR;
	$classObj = $prefix.preg_replace("/\./",DIRECTORY_SEPARATOR,$className);
	if(file_exists($classObj.".php")){
		_load($classObj);
	}
	else {
		echo _ExceptionString("Object [$className] Not found!");
		return false;
	}
}

/**
 * 内部调用，测试信息
 *
 * @param Array $param
 * @return Void
 */
function _debug($param){
	global $GO_CFG;
	if(!DEBUG){
		return;
	}
	$rand = time().rand(0,999999);
	$message ="<div id='debug_$rand' style='position:relative;border:1px dotted #E89B00;margin:3px;text-align:left;background-color:#E8E8E8;padding:3px;font-size:12px;padding-left:10px;' onmouseover=\"this.style.backgroundColor='#F1F1F1'\" onmouseout=\"this.style.backgroundColor='#E8E8E8'\">";
	$message .= "<div style='margin-left:-30px;border-bottom:1px solid #E89B00;font-weight:800;margin:0px;'>debug message (".date("Y-m-d H:i:s").")</div><ul style='margin:5px 5px 5px 20px;'>";
	$message .= "<li>File:&nbsp;".$param[0];
	$message .= "<li>Line:&nbsp;".$param[1];
	$message .= "<li>Message:&nbsp;".$param[2];
	$message .="</ul>";
	$message .="<div onclick=\"while(document.getElementById('debug_$rand').firstChild){document.getElementById('debug_$rand').removeChild(document.getElementById('debug_$rand').firstChild)}\" style='position:absolute;top:3px;right:15px;cursor:hand;border:1px solid #E89B00;padding:0px 3px 0px 3px'>X</div></div>\r\n";
	
	echo $message;
}

/**
 *  File() Extends
 *
 * @param String $filename
 * @return Array
 */
function _file($filename){
	$result = array();
	if(file_exists($filename) && is_readable($filename)){
		$result = file($filename);
	}
	return $result;
}

//LoadFile Success!
return md5(__FILE__);